package com.heima.schedule;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;


@SpringBootApplication
@MapperScan("com.heima.schedule.mapper")
@EnableScheduling//开启任务调度
public class ScheduleApplication {

    public static void main(String[] args) {
        SpringApplication.run(ScheduleApplication.class,args);
    }

    /**
     * mybatis-plus乐观锁支持
     * @return
     */
    @Bean//表明该方法将返回一个Spring管理的Bean实例
    public MybatisPlusInterceptor optimisticLockerInterceptor(){
        //创建了一个MybatisPlusInterceptor对象，这个对象是MyBatis Plus插件框架的主拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加了一个内部拦截器OptimisticLockerInnerInterceptor，这个拦截器是MyBatis Plus提供的乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //返回MybatisPlusInterceptor对象
        return interceptor;
    }
}
